package com.example.mvvm.data.db

import com.example.mvvm.data.model.place.City
import com.example.mvvm.data.model.place.County
import com.example.mvvm.data.model.place.Province
import org.litepal.LitePal

/*
本地数据库
 */
class PlaceDao {
    fun getProvinceList(): MutableList<Province> = LitePal.findAll(Province::class.java)

    fun saveProviceList(proviceList: List<Province>) {
        if (proviceList != null && proviceList.isNotEmpty()) {
            LitePal.saveAll(proviceList)
        }
    }

    fun getCityList(provinceId: Int): MutableList<City> = LitePal.where("provinceId=?",provinceId.toString()).find(City::class.java)

    fun saveCityList(cityList: List<City>) {
        if (cityList != null && cityList.isNotEmpty()) {
            LitePal.saveAll(cityList)
        }
    }

    fun getCountry(): MutableList<County> = LitePal.findAll(County::class.java)

    fun saveCountry(countyList: List<County>) {
        if (countyList != null && countyList.isNotEmpty()) {
            LitePal.saveAll(countyList)
        }
    }
}